# class Paginate(Resource):

#     def get(self):
#         rp = RequestParser()
#         rp.add_argument('page', required=True, type=int)
#         rp.add_argument('per_page', required=True, type=int)
#         args = rp.parse_args()
#         page = args.page
#         per_page = args.per_page
#         # 页 数是 paginate() 方法的第一个参数，也是唯一必需的参数。可选参数 per_page 用来指定 每页显示的记录数量；
#         # 当其设为 True 时（默认值），如果请求的页数超出了范围，则会返回 404 错误；如果 设为 False，页数超出范围时会返回一个空列表
#         res = Valve.query.paginate(page=page, per_page=per_page, error_out=False)
#         data = res.items
#         total = res.total  # 总条数
#         pages = res.pages  # 总页数
#         print(total, pages)
#         data = CommonSerializer(data).to_dict()
#         return {"code": 30001, 'data': data, "total": total, "pages": pages}


# from enum import Enum


# class UserType(Enum):
#     MALE = '男'
#     FEMALE = '女'


# class Device(db.Model):
#     __tablename__ = 'user'
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # unique=True 唯一的，不允许重复
#     log_ip = db.Column(db.String(256), nullbale=True, comment='IP')  # nullbale=True 允许为空
#     log_url = db.Column(db.String(256), comment='密码')
#     log_method = db.Column(db.String(256), comment='密码')
#     log_desc = db.Column(db.Text, comment='详细记录')
#     email = db.Column(db.String(120), index=True, nullable=True, default=None)  # 索引
#     gender = db.Column(db.Enum(UserType), nullable=False, default=UserType.MALE)

#     log_create_at = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')


# class User(db.Model):
#     __tablename__ = 'user'
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
#     username = db.Column(db.String(64), comment='用户名')
#     password = db.Column(db.String(256), comment='密码')

#     # 定义pwd的getter函数
#     @property
#     def pwd(self):
#         return self.password  # 加密之后的密文

#     # 定义pwd的setter函数
#     @pwd.setter
#     def pwd(self, x_password):
#         '''
#         根据明文的密码，加密得到密文
#         :param x_password: 密码的明文
#         :return: 加密之后的密文
#         '''
#         self.password = generate_password_hash(x_password)  # 根据flask提供的算法来加密

#     def check_password(self, x_password):
#         '''
#         验证密码是否正确
#         :param x_password: 密码的明文
#         :return:
#         '''
#         return check_password_hash(self.password, x_password)

# class Function(db.Model):
#     __tablename__ = 'function_schema'
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键ID')
#     name = db.Column(db.Text, comment='模型名字')
#     title = db.Column(db.String(64), comment='标题')
#     properties = db.Column(db.Text, comment='属性')

#     def __repr__(self):
#         return f"当前data的id{self.title},当前sheet的id是{self.id}"


# # class Project(db.Model):
# #     __tablename__ = 'project'
# #     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# #     project_name = db.Column(db.String(64), comment='项目名称')
# #     project_desc = db.Column(db.String(128), comment='项目描述')
# #     project_db_id = db.Column(db.String(128), unique=True, comment='项目id')
# #
# #     # project = db.relationship('Sheet', backref='project1', lazy='dynamic', cascade='all, delete')

# # class Project(db.Model):
# #     __tablename__ = 'project'
# #     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# #     project_name = db.Column(db.String(64), comment='项目名称')
# #     project_desc = db.Column(db.String(128), comment='项目描述')
# #     project = db.relationship('Sheet', backref='project1', lazy='dynamic', cascade='all, delete')

# #     def __repr__(self):
# #         return f"当前的项目名称{self.project_name}"


# # class Sheet(db.Model):
# #     __tablename__ = 'sheet'
# #     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# #     sheet_name = db.Column(db.String(64), comment='工作表')
# #     project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
# #     instrument = db.relationship('Instrument', backref='sheet', lazy='dynamic', cascade='all, delete')  # 级联删除

# #     def __repr__(self):
# #         return f"当前的工作表{self.sheet_name}"
# # class Model(db.Model):
# #     __tablename__ = 'db_model'
# #     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# #     device_name = db.Column(db.String(255), comment='设备')
# #     model_name = db.Column(db.String(255), comment='Model Name')
# #     model_properties = db.Column(db.Text, comment='Model Properties')

# #     def __repr__(self):
# #         return f"当前的id是{self.id},当前的仪器编号{self.device_name}"

# # def paginate(data, page, curpage):
# # # 原始数据列表
# # data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

# # # 每页显示的数据量
# # page_size = 5

# # # 当前页码
# # page_number = 2  # 页码从1开始

# # # 计算切片的起始索引和结束索引
# # start_index = (page_number - 1) * page_size
# # end_index = page_number * page_size

# # # 使用切片获取当前页的数据
# # current_page_data = data[start_index:end_index]

# # # 打印结果
# # print(current_page_data)
